package yyds.sniarbtej.transformer;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;

public final class HideAgentStrings extends BaseClassTransformer {
    public String canTransformClassName() {
        return "kotlin/text/StringsKt__StringsKt";
    }

    public byte[] rewrite(byte[] in) {
        return transform(in, new ClassRewriter() {
            @Override
            public void rewriteMethod(MethodNode node) {
                if ("contains".equals(node.name) && "(Ljava/lang/CharSequence;Ljava/lang/CharSequence;Z)Z".equals(node.desc)) {
                    InsnList insn = new InsnList();
                    LabelNode labelNode = new LabelNode();
                    insn.add(labelNode);
                    insn.add(new VarInsnNode(Opcodes.ALOAD, 0));
                    insn.add(new VarInsnNode(Opcodes.ALOAD, 1));
                    insn.add(new MethodInsnNode(Opcodes.INVOKESTATIC, methodOverride, "C1", "(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Z", false));
                    labelNode = new LabelNode();
                    insn.add(new JumpInsnNode(Opcodes.IFEQ, labelNode));
                    insn.add(new InsnNode(Opcodes.ICONST_0));
                    insn.add(new InsnNode(Opcodes.IRETURN));
                    insn.add(labelNode);
                    node.instructions.insert(insn);
                }
            }
        });
    }
}
